package com.xcity.game.activity.newplayer.tracer;

import java.text.MessageFormat;

import com.xcity.db.entity.Employee;
import com.xcity.game.activity.newplayer.NewPlayerDoingStr;
import com.xcity.game.activity.newplayer.NewPlayerTask;
import com.xcity.game.activity.newplayer.NewPlayerTracer;
import com.xcity.game.activity.newplayer.NewPlayerTracerLabel;

@NewPlayerTracerLabel(NewPlayerTracer.EMPLOYEE_STAR)
public class EmployeeStarTracer implements NewPlayerTracer{

	@Override
	public boolean isDone(NewPlayerTask task) {
		int[] params = task.getTemplate().getParam();
		int[] progress = task.getProgress();
		if(params[0] == 1){
			//看等级
			if(progress[0] == 1 && progress[1] >= params[1]){
				return true;
			}
		}else{
			if(progress[0] >= params[0] && progress[1] >= params[1]){
				return true;
			}
		}
		return false;
	}

	@Override
	public void onChange(NewPlayerTask task, Object... vals) {
		// TODO Auto-generated method stub
		int oldStar = (int) vals[2];
		int newStar = 0;
		Employee e = (Employee)vals[1];
		if(e != null){
			newStar = e.getStarLvl();
		}
		int[] params = task.getTemplate().getParam();
		int[] progress = task.getProgress();
		if(params[0] == 1){
			//统计等级
			if(oldStar < params[1] && newStar >= params[1]){
				progress[0] = 1;
			}
			if(newStar > progress[1]){
				progress[1] = newStar;
			}
		}else{
			if(oldStar < params[1] && newStar >= params[1]){
				progress[0] = progress[0] + 1;
			}
			if(progress[0] == 0){
				progress[1] = newStar;
			}else{
				progress[1] = params[1];
			}
		}
		if(progress[0] > PARAM0_MAX){
			progress[0] = PARAM0_MAX;
		}
		if(progress[1] > PARAM1_MAX){
			progress[1] = PARAM1_MAX;
		}
	}

	@Override
	public String getDoingStr(NewPlayerTask task) {
		int[] params = task.getTemplate().getParam();
		if(params[0] == 1){
			return MessageFormat.format(NewPlayerDoingStr.STR_EMPLOYEE_STAR, params[1]);
		}
		return MessageFormat.format(NewPlayerDoingStr.STR_EMPLOYEE_STAR_MULTI, params[0], params[1]);
	}

}
